/**
 * Created by asus on 2017/5/5.
 */
const faker = require('faker')
const lib = require('lodash')
faker.locale = 'zh_CN'

module.exports = {
  api: '/codi-admin-mock/sys/news/search',
  response: function (req, res) {
    console.log(req.query)
    let index = parseInt(req.query.page)
    let size = parseInt(req.query.size)
    let keyword = req.query.keyword;
    const total = 36
    const page = Math.ceil(total / size)
    let resNum = index >= page ? (total - (index - 1) * size) : size
    let content = `这是搜索:${keyword}`;
    let data = {
      'success': true,
      'objs': lib.times(resNum, function (n) {
        return {
          'content': '这是征文',
          'from': '腾讯证券',
          'fromUrl': 'http://baidu.com',
          'id': n + ((index - 1) * size),
          'keyword': '老虎 QFII',
          'location': (n % 2 === 1) ? 'PC' : 'APP',
          'modifyDate': 1493802512051,
          'publishDate': 1493802512051,
          'publisher': 'admin',
          'status': (n % 2 === 1) ? '上线' : '下线',
          'title': content + (n + ((index - 1) * size))
        }
      }),
      'page': index,
      'rowCount': resNum,
      'size': resNum,
      'totalNum': total,
      'totalPage': page
    }
    res.json(data)
  }
}
